package com.system.demo.mapper.auth;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.system.demo.entity.auth.SystemRoleMenu;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SystemRoleMenuMapper extends BaseMapper<SystemRoleMenu> {

    /**
     * 根据 roleId 获取对应的 menuIds
     */
    @Select("SELECT menu_id FROM system_role_menu WHERE role_id = #{roleId}")
    List<Integer> getMenuIdsByRoleId(@Param("roleId") Integer roleId);

    /**
     * 批量删除角色菜单绑定关系
     *
     * @param roleId 角色 ID
     * @param menuIds 菜单 ID 列表
     */
    @Delete({
            "<script>",
            "DELETE FROM system_role_menu",
            "WHERE role_id = #{roleId}",
            "AND menu_id IN",
            "<foreach collection='menuIds' item='menuId' open='(' separator=',' close=')'>",
            "#{menuId}",
            "</foreach>",
            "</script>"
    })
    int batchDeleteRoleMenus(@Param("roleId") Integer roleId, @Param("menuIds") List<Integer> menuIds);
}
